@extends('frontend.default.app')
@section('content')
    <!-- banner部分 -->
    <div class="banner news">
        <div class="title">
            <p>资源家</p>
            <p class="en">一个乐于分享的网站——分享历程，记录经验，积累点滴，实现自我...</p>
        </div>
    </div>
    <!-- main -->
    <div class="main-news">
        <div class="layui-container">
            <div class="layui-row layui-col-space20">

                @foreach( $posts as $post)
                    <div class="layui-col-lg6 content">
                        <div>
                            <div class="news-img"><a href="{{route('post',$post['id'])}}"><img src="{{get_thumb($post['post_thumb'])}}"></a></div><div class="news-panel">
                                <strong><a href="{{route('post',$post['id'])}}">{{$post['title']}}</a></strong>
                                <p class="detail"><span>{{cut_str($post['post_content'],0,70)}}</span><a href="{{route('post',$post['id'])}}">[详细]</a></p>
                                <p class="read-push">发布时间：<span>{{time_ago($post['created_at'])}}</span></p>
                            </div>
                        </div>
                    </div>
                @endforeach
                    <div id="userPage" style=" clear: both">
                        {{ $paginator }}  //分页
                    </div>
                <div id="demo0"></div>
            </div>

        </div>
    </div>

@endsection

@section('script')
    <script>
        layui.use(['laypage', 'layer','jquery'], function(){
            var laypage = layui.laypage
                ,$ = layui.jquery
                ,layer = layui.layer;


            var count = "{{$total}}";
            var cur_page = "{{$current_page}}";
            var limit = "{{$perPage}}";
            var txt = "{{$txt}}";
            laypage.render({
                elem: 'userPage'
                ,curr:cur_page
                ,count: count
                ,limit:limit
                ,txt:txt
                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,jump: function(obj,first){
                    // console.log(obj)
                    //url =window.location.href;
                    url = window.location.pathname;//当前页url不带参
                    var params = {page:obj.curr, per_num:obj.limit};
                    if(!empty(txt)){
                        params['searchq']=txt; //这个是搜索 参数
                    }
                    //url = http_build_query(url, params);
                    var pa =$.param(params);
                    if(!first){  //跳转必须放在这个里边，不然无限刷新
                       // window.location.href= url; //跳转
                        window.location.href= url+'?'+pa; //跳转
                    }
                }
            });
        });

        function empty(mixed_var) {
            var undef, key, i, len;
            var emptyValues = [undef, null, false, 0, "", "0"];
            for (i = 0, len = emptyValues.length; i < len; i++) {
                if (mixed_var === emptyValues[i]) {
                    return true
                }
            }
            if (typeof mixed_var === "object") {
                for (key in mixed_var) {
                    return false
                }
                return true
            }
            return false
        };
    </script>
@endsection